# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import List
from fastapi import APIRouter, Depends, Request
from hypertext import R, response_json
from apps.admin.schemas.market import subscribe_schema as schema
from apps.admin.service.market.subscribe_service import SubscribeService

router = APIRouter(prefix="/subscribe", tags=["订阅套餐"])


@router.get("/pricing", summary="套餐定价", response_model=R[List[schema.SubscribePricingVo]])
@response_json
async def pricing(params: schema.SubscribePricingIn = Depends()):
    return await SubscribeService.pricing(params.user_id, params.calendar)


@router.get("/lists", summary="套餐列表", response_model=R[List[schema.SubscribePackageListVo]])
@response_json
async def lists():
    return await SubscribeService.lists()


@router.get("/detail", summary="套餐详情", response_model=R[schema.SubscribeDetailVo])
@response_json
async def detail(params: schema.SubscribeDetailIn = Depends()):
    return await SubscribeService.detail(params.id)


@router.get("/models", summary="套餐模型", response_model=R)
@response_json
async def models():
    return await SubscribeService.models()


@router.post("/add", summary="套餐新增", response_model=R)
@response_json
async def add(params: schema.SubscribeAddIn):
    return await SubscribeService.add(params)


@router.post("/edit", summary="套餐编辑", response_model=R)
@response_json
async def edit(params: schema.SubscribeEditIn):
    return await SubscribeService.edit(params)


@router.post("/delete", summary="套餐删除", response_model=R)
@response_json
async def delete(params: schema.SubscribeDeleteIn):
    return await SubscribeService.delete(params.id)


@router.get("/get_config", summary="配置读取", response_model=R[schema.SubscribeConfigIn])
@response_json
async def get_config():
    return await SubscribeService.get_config()


@router.post("/set_config", summary="配置修改", response_model=R)
@response_json
async def set_config(params: schema.SubscribeConfigIn):
    return await SubscribeService.set_config(params)


@router.post("/open_vip", summary="配置修改", response_model=R)
@response_json
async def open_vip(request: Request, params: schema.SubscribeOpenIn):
    admin_id: int = int(request.state.admin_id)
    return await SubscribeService.open_vip(admin_id, params)
